/* 
包含n个接口请求函数的模块
每个接口返回一个promise对象
*/
import axios from 'axios'
import { SearchUserReponse } from './types'

axios.interceptors.response.use((response) => {
  return response.data
})
/* 
get<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
*/

// 前提是响应拦截器成功回调不是返回response.data
// export const reqSearchUsers = (keyword: string) => axios.get<SearchUserReponse>('/dev-api/search/users', {
//   params: {q: keyword}
// })

// 如果响应拦截器成功回调返回的是response.data
export const reqSearchUsers = (keyword: string) => axios.get<any, SearchUserReponse>('/dev-api/search/users', {
  params: {q: keyword}
})

/* 
axios请求成功的value是response对象, 失败的reason是error对象
  response: {data: 请求体数据}
  error: {message: 字符串}
*/
reqSearchUsers('aa').then((result) => {
  console.log(result.items)
})